import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import '../../../app_files.dart';
import 'action.dart';
import 'state.dart';

Widget buildView(
    OrderResultEditState state, Dispatch dispatch, ViewService viewService) {
  Widget _infoWidget() => Container(
    padding: EdgeInsets.only(left: 15, right: 15, bottom: 8),
    decoration: BoxDecoration(
        color: Colors.white,
        border: Border(
            bottom: BorderSide(color: ThemeConfig.separeColor, width: 10))),
    child: Column(
      children: [
        Container(
          height: 44,
          child: Align(
            alignment: Alignment.centerLeft,
            child: Text(
              '客户信息',
              style: TextThemeConfig.Font16WithColorBold22,
            ),
          ),
          margin: EdgeInsets.only(bottom: 4),
        ),
        Container(
          padding: EdgeInsets.symmetric(vertical: 5),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                width: 85,
                child:  Text(
                  '客户姓名',
                  style: TextThemeConfig.Font14WithColor66,
                ),
              ),
              Expanded(child: Text(
                state.model.userName ,
                style: TextThemeConfig.Font14WithColor22,
              ),)
            ],
          ),
        ),
        Container(
          padding: EdgeInsets.symmetric(vertical: 6),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                width: 85,
                child:  Text(
                  '客户地址',
                  style: TextThemeConfig.Font14WithColor66,
                ),
              ),
              Expanded(
                child: Text(
                  state.model.userAddress,
                  style: TextThemeConfig.Font14WithColor22,
                ),
              ),
            ],
          ),
        ),
        Container(
          padding: EdgeInsets.symmetric(vertical: 5),
          child: Row(
            children: [
              Container(
                width: 85,
                child: Text(
                  '联系方式',
                  style: TextThemeConfig.Font14WithColor66,
                ),
              ),
              Text(
                state.model.phone,
                style: TextThemeConfig.Font14WithColor22,
              ),
            ],
          ),
        ),
        Container(
          padding: EdgeInsets.symmetric(vertical: 5),
          child: Row(
            children: [
              Container(
                width: 85,
                child: Text(
                  '表号',
                  style: TextThemeConfig.Font14WithColor66,
                ),
              ),
              Text(
                state.model.meterNo,
                style: TextThemeConfig.Font14WithColor22,
              ),
            ],
          ),
        ),
      ],
    ),
  );

  Widget _editWidget() => Container(
        padding: EdgeInsets.only(left: 15, right: 15, bottom: 0),
        decoration: BoxDecoration(color: Colors.white),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding: EdgeInsets.only(top: 8, bottom: 8),
              child: Text(
                '安检信息',
                style: TextThemeConfig.Font16WithColorBold22,
              ),
            ),
            Expanded(
              child: Container(
                padding: EdgeInsets.only(bottom: 0),
                child: TextField(
                  minLines: 1,
                  maxLines: 100,
                  controller: state.textEditingController,
                  style: TextThemeConfig.Font14WithColor22,
                  strutStyle: StrutStyle(forceStrutHeight: true, height: 0.8, leading: 0.9),
                  decoration: InputDecoration(
                    border: InputBorder.none,
                    hintText: "请在此处描述问题...",
                    hintStyle: TextThemeConfig.Font14WithColor99,
                    contentPadding: EdgeInsets.only(top: 0),
                  ),
                  onChanged: (String str) {
                    if (str.length > ThemeConfig.descTextLength)
                      state.textEditingController.text =
                          str.substring(0, ThemeConfig.descTextLength);
                  },
                ),
              ),
            ),
          ],
        ),
      );

  Widget _confirmButton() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 15, vertical: 30),
      height: 50,
      decoration: BoxDecoration(
        color: ThemeConfig.mainColor,
        borderRadius: BorderRadius.all(Radius.circular(4)),
      ),
      child: InkWell(
        child: Align(
          child: Text(
            '复制信息',
            style: TextThemeConfig.Font16WithWhite,
          ),
        ),
        onTap: () => dispatch(OrderResultEditActionCreator.onSubmit()),
      ),
    );
  }

  return Scaffold(
    appBar: myAppBar(viewService.context, title: '分享安检工单'),
    resizeToAvoidBottomPadding: false,
    body: GestureDetector(
      onTap: () => CommonUtils.closeKey(viewService.context),
      behavior: HitTestBehavior.translucent,
      child: SafeArea(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            _infoWidget(),
            Expanded(
              child: _editWidget(),
            ),
            _confirmButton(),
          ],
        ),
      ),
    ),
  );
}
